<template>
  <div class="dynamicicle-container">
    <!--面包导航区域  -->
    <breadcrumb></breadcrumb>

    <!-- 塞选卡片1 -->
    <el-card class="box-card">
      <!-- 标题 -->
      <div slot="header" class="clearfix">
        <span>塞选内容</span>
      </div>
      <!-- 艺术涂料塞选表单 -->
      <el-form ref="form" :model="queryInfo" label-width="40px" size="small">
        <!-- 内容管理状态 -->
        <el-form-item label="分类">
          <el-radio-group v-model="queryInfo.query">
            <el-radio label="">全部</el-radio>
            <el-radio label="案例">案例</el-radio>
            <el-radio label="加盟">加盟</el-radio>
            <el-radio label="新闻">新闻</el-radio>
          </el-radio-group>
        </el-form-item>


        <!-- 塞选按钮 -->
        <el-form-item>
          <el-button type="primary" @click="this.loadDynamic">塞选</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 艺术涂料内容卡片2 -->
    <el-card style="margin-top: 15px">
      <div slot="header" class="clearfix" style="display:flex;justify-content: space-between;align-items: center;">
        <div>根据塞选条件共查询到 {{ total_count }} 条结果</div>
        <div class="add"> <el-button type="primary" @click="dynamicAdd">添加</el-button></div>
      </div>

      <!-- 艺术涂料表格 -->
      <el-table
        :data="dynamic"
        stripe
        style="width: 100%"
        :default-sort = "{prop:'pubdate',order: 'descending'}"
      >
      <el-table-column prop="img" label="封面" width="180">
        <template slot-scope="scope">
            <el-image
              v-if="scope.row.img"
              style="width: 100px; height: 100px"
              :src="scope.row.img"
              fit="fill"
              :preview-src-list="[scope.row.img]"
            ></el-image>
            <img v-else style="width: 100px; height: 100px" src="../../assets/images/noImg.jpg" alt="">
          </template>
      </el-table-column>
      <el-table-column prop="title" label="标题"> </el-table-column>
      <el-table-column prop="EnglishName" label="英文名"> </el-table-column>
      <el-table-column prop="pubdate" label="发布时间" > </el-table-column>
      <el-table-column label="操作">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="修改信息" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="dynamicEidt(scope.row.id)"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top" >
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="deleteDialog(scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2,5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total_count"
      >
      </el-pagination>
    </el-card>

    <!-- 删除艺术涂料对话框 -->
    <el-dialog title="删除" :visible.sync="deleteDialogVisble" width="50%">
      <span>您确定删除吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisble = false">取消</el-button>
        <el-button type="primary" @click="deleteDynamic">确定</el-button>
      </span>
    </el-dialog>
    
  </div>
</template>

<script>
import Breadcrumb from "@/components/Breadcrumb.vue";
import {postDynamic,postDeleteDynamic} from "@/api/dynamic.js";
export default {
  components: {
    Breadcrumb,
  },
  data() {
    return {
      //艺术涂料表格数据
      dynamic: [
        // pubdate
      ],
      //艺术涂料请求参数
      queryInfo: {
        pagenum: 1,
        pagesize: 5,
        query: "",
      },
      //艺术涂料总数
      total_count: null,
      //艺术涂料删除参数
      deleteParams:{
        id:null
      },
      //删除艺术涂料对话框显示隐藏
      deleteDialogVisble:false,
    };
  },
  computed: {},
  methods: {
    //获取艺术涂料数据
    async loadDynamic() {
      const { data: res } = await postDynamic(this.queryInfo);
      console.log(res);
      
      this.dynamic = res.datas.dynamic;
      console.log(this.dynamic)
      this.total_count = res.datas.total;
    },
    //删除艺术涂料
    // async
    //监听pape改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.loadDynamic();
    },
    //监听per_page改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.loadDynamic();
    },
    //去艺术涂料添加区域
    dynamicAdd(){
      this.$router.push('/dynamic/add')
    },
    dynamicEidt(id){
      this.$router.push('/dynamic/edit/'+ id)
    },
    deleteDialog(row){
      console.log(row)
      this.deleteDialogVisble = true
      this.deleteParams = {
        id:row.id
      }
    },
    //删除艺术涂料
    async deleteDynamic(){
      const {data:res} = await postDeleteDynamic(this.deleteParams)
      if(res.meta.status !== 200) return this.$message.error('删除艺术涂料信息失败')
      this.$message.success('删除艺术涂料信息成功')
      this.deleteDialogVisble = false
      this.loadDynamic()
    }
  },
  created() {
    //调用艺术涂料数据
    this.loadDynamic();
    
  },
  mounted() {
  },
};
</script>

<style lang='less' scoped>
.dynamicicle-cover {
  width: 50%;
  background-size: cover;
}
</style>